package com.yeyi.ytest;

import java.util.ArrayList;
import java.util.List;

import com.alibaba.fastjson.JSON;

class TestTS{
    private int i = 0;
    private String s = "123";
    private List<Integer> list = new ArrayList<>();
    public int getI() {
        return i;
    }
    public void setI(int i) {
        this.i = i;
    }
    public String getS() {
        return s;
    }
    public void setS(String s) {
        this.s = s;
    }
    public List<Integer> getList() {
        return list;
    }
    public void setList(List<Integer> list) {
        this.list = list;
    }
    
    @Override
    public String toString() {
        return "TestTS [i=" + i + ", s=" + s + ", list=" + list + "]";
    }
    
}

public class ToStringTest {
    public static void main(String[] args) {
        TestTS t = new TestTS();
        System.out.println(t.toString());
        
        List<TestTS> list = new ArrayList<>();
        list.add(t);
        list.add(t);
        list.add(t);
//        System.out.println(list); // list 会自动将里面 toString 输出而不是输出地址
        System.out.println(JSON.toJSONString(list,true));
    }
}
// 输出：
//TestTS [i=0, s=123, list=[]]
//[TestTS [i=0, s=123, list=[]], TestTS [i=0, s=123, list=[]], TestTS [i=0, s=123, list=[]]]
// 去掉 toString 重载输出:
//com.yeyi.ytest.TestTS@182decdb
//[com.yeyi.ytest.TestTS@182decdb, com.yeyi.ytest.TestTS@182decdb, com.yeyi.ytest.TestTS@182decdb]

